package com.group.transaction.service.integralLog.impl;

import com.group.transaction.domain.IntegralLog;
import com.group.transaction.domain.User;
import com.group.transaction.mapper.IntegralLogMapper;
import com.group.transaction.model.ResultJson;
import com.group.transaction.service.integralLog.IntegralLogService;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IntegralLogServiceImpl implements IntegralLogService {

    @Resource
    private IntegralLogMapper integralLogMapper;
    /**
     * 查询用户积分日志
     * @return
     */
    @Override
    public ResultJson queryIntegralLogByUserId(IntegralLog integralLog){
        User user = (User) SecurityUtils.getSubject().getSession().getAttribute("user");
        integralLog.setUserId(user.getId());
        List<IntegralLog> integralLogList = integralLogMapper.queryIntegralLogByUserId(integralLog);
        Map<String,Object> map = new HashMap<>();
        map.put("list",integralLogList);
        map.put("total",integralLogMapper.queryIntegralLogTotalByUserId(integralLog));
        if(integralLogList != null && integralLogList.size() > 0) {
            return ResultJson.builder().code(1).message("有数据").result(map).build();
        } else {
            return ResultJson.builder().code(-1).message("无数据").result(integralLogList).build();
        }
    }
    /**
     * 查询所有用户积分日志
     * @returna
     */
    @Override
    public ResultJson queryIntegralLogAllData(IntegralLog integralLog){
        List<IntegralLog> integralLogList = integralLogMapper.queryIntegralLogByUserId(integralLog);
        Map<String,Object> map = new HashMap<>();
        map.put("list",integralLogList);
        map.put("total",integralLogMapper.queryIntegralLogTotalByUserId(integralLog));
        if(integralLogList != null && integralLogList.size() > 0) {
            return ResultJson.builder().code(1).message("有数据").result(map).build();
        } else {
            return ResultJson.builder().code(-1).message("无数据").result(integralLogList).build();
        }
    }
}
